<if condition="$field['type'] neq 'hidden'">
<div class="am-cf am-form-group">
    <label class="am-u-sm-2 am-form-label">{$field.title|htmlspecialchars}</label>
    <if condition="$field['name'] == 'action'">
        <p style="color: #f00;">开发人员注意：你使用了一个名称为action的字段，由于这个字段名称会与form[action]冲突，导致无法提交表单，请换用另外一个名字。</p>
    </if>
    <div class="am-u-sm-10 ">
    <switch name="field.type">
        <case value="text">
            <input type="text" name="{$field.name}" value="{$field.value|htmlspecialchars}" class="am-form-field" style="width: 400px"/>
        </case>

        <case value="label">
            {$field.value}
        </case>
        <case value="readonly">
            <input type="text" name="{$field.name}" value="{$field.value}" class="am-form-field" placeholder="无需填写" readonly/>
        </case>
        <case value="integer">
            <input type="text" name="{$field.name}" value="{$field.value}" class="am-form-field" />
        </case>
        <case value="uid">
            <input type="text" name="{$field.name}" value="{$field.value}" class="am-form-field" />
        </case>
        <case value="select">
            <select name="{$field.name}" class="am-form-field" style="width:auto;">
                <volist name="field.opt" id="option">
                    <php>
                        $selected = $field['value']==$key ? 'selected' : '';
                    </php>
                    <option value="{$key}"
                    {$selected}>{$option|htmlspecialchars}</option>
                </volist>
            </select>
        </case>
        <case value="radio">
            <volist name="field.opt" id="option">
                <php>
                    $checked = $field['value']==$key ? 'checked' : '';
                    $inputId = "id_$field[name]_$key";
                </php>
                <label for="{$inputId}"> <input id="{$inputId}" name="{$field.name}" value="{$key}" type="radio" {$checked}/> {$option|htmlspecialchars}</label>
            </volist>
        </case>

        <case value="singleImage">
            <input type="file" id="upload_picture_{$field.name}">
            <input type="hidden" name="{$field.name}" id="cover_id_{$field.name}"/>
            <div class="upload-img-box">
            <notempty name="data[$field['name']]">
                <div class="upload-pre-item"><img src="{$data[$field['name']]|get_cover='path'}"/></div>
            </notempty>
            </div>
            <script type="text/javascript">
            //上传图片
            /* 初始化上传插件 */
            $("#upload_picture_{$field.name}").uploadify({
                "height"          : 30,
                "swf"             : "__PUBLIC__/uploadify/uploadify.swf",
                "fileObjName"     : "download",
                "buttonText"      : "上传图片",
                "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                "width"           : 120,
                'removeTimeout'   : 1,
                'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                "onUploadSuccess" : uploadPicture{$field.name},
                'onFallback' : function() {
                    alert('未检测到兼容版本的Flash.');
                }
            });
            function uploadPicture{$field.name}(file, data){
                var data = $.parseJSON(data);
                var src = '';
                if(data.status){
                    $("#cover_id_{$field.name}").val(data.id);
                    src = data.url || '__ROOT__' + data.path
                    $("#cover_id_{$field.name}").parent().find('.upload-img-box').html(
                        '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                    );
                } else {
                    updateAlert(data.info);
                    setTimeout(function(){
                        $('#top-alert').find('button').click();
                        $(that).removeClass('disabled').prop('disabled',false);
                    },1500);
                }
            }
            </script>
        </case>

        <case value="multiImage">
            <input type="file" id="upload_pictures_{$field.name}">
            <input type="hidden" name="{$field.name}" value="{$valStr}" class="icon {$field.name}" />
            <div class="upload-img-box">
                <notempty name="data[$field['name']]">
                     <volist name="data[$field['name']]" id="v">
                        <div class="upload-pre-item">
                            <img src="__ROOT__{$v|get_cover='path'}" data-id="{$v}"/>
                            <span class='btn-close btn-close-{$field.name}' title='删除图片'></span>
                        </div>
                     </volist>
                </notempty>
            </div>

            <script type="text/javascript">
                //上传图片
                $(function(){
                    /* 初始化上传插件*/
                    $("#upload_pictures_{$field.name}").uploadify({
                        "height"          : 30,
                        "swf"             : "__PUBLIC__/uploadify/uploadify.swf",
                        "fileObjName"     : "download",
                        "buttonText"      : "上传多图",
                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                        "width"           : 120,
                        'removeTimeout'   : 1,
                        'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                        "onUploadSuccess" : uploadPicture{$field.name},
                        'onFallback' : function() {
                            alert('未检测到兼容版本的Flash.');
                        }
                    });
                    $('.btn-close-{$field.name}').click(function(event) {
                        event.preventDefault();
                        $(this).parent().remove();
                        picsbox = $("#upload_pictures_{$field.name}").siblings('.upload-img-box');
                        picArr = [];
                        for (var i = 0; i < picsbox.children().length ; i++) {
                            picArr.push(picsbox.children('.upload-pre-item:eq('+i+')').find('img').attr('data-id'));
                        };
                        picStr = picArr.join(',');
                        $('.icon.{$field.name}').val(picStr);
                    });
                })
                function uploadPicture{$field.name}(file, data){
                    var data = $.parseJSON(data);
                    var src = '';
                    if(data.status){
                        src = data.url || '__ROOT__' + data.path;
                        upload_img = "<div class='upload-pre-item'><img src=" + src +" title='点击显示大图' data-id="+data.id+"> <span class='btn-close btn-close-{$field.name}' title='删除图片'></span></div>";
                        picsbox = $("#upload_pictures_{$field.name}").siblings('.upload-img-box');
                        picsbox.append(upload_img)
                        picArr = [];
                        for (var i = 0; i < picsbox.children().length ; i++) {
                            picArr.push(picsbox.children('.upload-pre-item:eq('+i+')').find('img').attr('data-id'));
                        };
                        picStr = picArr.join(',');
                        $('.icon.{$field.name}').val(picStr);
                    } else {
                        updateAlert(data.info);
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        },1500);
                    }
                }
            </script>
        </case>

        <case value="checkbox">
            <php>
                $importCheckBox = true;
            </php>
            <php>
                $field['value_array'] = explode(',', $field['value']);
            </php>
            <volist name="field.opt" id="option">
                <php>
                    $checked = in_array($key,$field['value_array']) ? 'checked' : '';
                    $inputId = "id_$field[name]_$key";
                </php>
                <label for="{$inputId}"> <input type="checkbox" value="{$key}" id="{$inputId}" class="oneplus-checkbox" data-field-name="{$field.name}" {$checked}/> {$option|htmlspecialchars}</label>

            </volist>
            <input type="hidden" name="{$field.name}" class="oneplus-checkbox-hidden" data-field-name="{$field.name}" value="{$field.value}"/>
        </case>
        <case value="editor">
            {:W('Common/Editor/run',array($field['name'],$field['value']))}
        </case>
        <case value="textarea">
            <textarea name="{$field.name}" class="am-form-field" style="height:120px;">{$field.value|htmlspecialchars}</textarea>
        </case>
        <case value="time">
            <php>
                $importDatetimePicker = true;
                //默认为当前时间
                if(!$field['value']){
                $field['value'] = time();
                }
            </php>
            <input type="hidden" name="{$field.name}" value="{$field.value}"/>
            <input type="text" data-field-name="{$field.name}" class="time am-form-field" value="{$field.value|time_format}" placeholder="请选择时间" style="width:auto;" />
        </case>

        <!--添加城市选择（需安装城市联动插件,css样式不好处理排版有点怪）-->
        <case value="city">
                <style type="text/css">
        			.am-form-field {
    				display:inline-block;
    				width: 120px;
    				}
    			</style>
                <!--修正在编辑信息时无法正常显示已经保存的地区信息-->
                {:hook('J_China_City',array('province'=>$field['value']['0'],'city'=>$field['value']['1'],'district'=>$field['value']['2'],'community'=>$field['value']['3']))}
        </case>

        <!--弹出窗口选择并返回值（目前只支持返回ID）开始-->
        <case value="dataselect">
            <input type="text" name="{$field.name}" id="{$field.name}" value="{$field.value|htmlspecialchars}" class="am-form-field"/><input class="am-btn am-btn-default" style="margin-left:10px" type="button" value="选择" onclick="openwin('{$field.opt}','600','500')">
		     <script type="text/javascript">
					//弹出窗口
					function openwin(url,width,height){
					    var l=window.screen.width ;
					    var w= window.screen.height;
					    var al=(l-width)/2;
					    var aw=(w-height)/2;
					    var OpenWindow=window.open(url,"弹出窗口","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width="+width+",height="+height+",top="+aw+",left="+al+"");
					    OpenWindow.focus();
					if(OpenWindow!=null){ //弹出窗口关闭事件
					//if(window.attachEvent) OpenWindow.attachEvent("onbeforeunload",   quickOut);
					if(window.attachEvent) OpenWindow.attachEvent("onunload",   quickOut);
					}
					}
					//关闭触发方法
					function quickOut()
					{
					alert("窗口已关闭");
					}
			 </script>
        </case>
    	<!--弹出窗口选择并返回值（目前只支持返回ID）结束-->

        <case value="kanban">

            <input type="hidden" name="{$field.name}" value='{:json_encode($field["value"])}'/>
            <div class="kanbans" id="{$field.name}">
                <php>foreach($field['value'] as $key =>$kanban){</php>
                <div class="kanban panel" data-id="{$kanban['data-id']}" data-title="{$kanban['title']}">
                    <div class="panel-heading">
                        <strong>{$kanban['title']}</strong>
                    </div>
                    <div class="panel-body">
                        <div class="kanban-list">
                            <volist name="kanban.items" id="vo">
                                <div class="kanban-item item" data-id="{$vo.data-id}" data-title="{$vo.title}">
                                    {$vo.title}
                                </div>
                            </volist>
                        </div>
                    </div>
                </div>
                <php>}</php>
            </div>
            <script>
                $(function () {
                    var flag = "{$field.name}"
                    $('#{$field.name}').kanbans({'drop': function () {
                        var kanban =new Array();
                        $('.kanbans .kanban').each(function (index, element) {
                            if ($(element).data('id')) {
                                kanban[index] =  new Object();
                                kanban[index]['data-id'] =  $(element).data('id');
                                kanban[index]['title'] =  $(element).data('title');
                                kanban[index]['items'] =  new Array();
                                var obj = $(element).find('.item');
                                for (var i = 0; i < obj.length; i++) {
                                    kanban[index]['items'][i] = new Object();
                                    kanban[index]['items'][i]['data-id'] = $(obj[i]).data('id');
                                    kanban[index]['items'][i]['title'] = $(obj[i]).data('title');
                                };
                            }
                        })
                        var kanban_str = JSON.stringify(kanban);
                        $('[name="'+flag+'"]').val(kanban_str);
                    }
                    })
                })
            </script>

        </case>
    <case value="chosen">
        <select name="{$field.name}[]" class="chosen-select" multiple="multiple">
            <php>
                if( key($field['opt']) === 0){
            </php>
            <volist name="field['opt']" id="option">
                <php>
                    $selected = in_array(reset($option),$field['value'])? 'selected' : '';
                </php>
                <option value="{:reset($option)}" {$selected}>{$option|end|htmlspecialchars}</option>
            </volist>
            <php>
                }else{
                foreach($field['opt'] as $optgroupkey =>$optgroup){
            </php>
            <optgroup label="{$optgroupkey}">
                <volist name="optgroup" id="option">
                    <php>
                        $selected = in_array(reset($option),$field['value'])? 'selected' : '';
                    </php>
                    <option value="{:reset($option)}" {$selected}>{$option|end|htmlspecialchars}</option>
                </volist>
            </optgroup>
            <php>
                }
                }
            </php>
        </select>
    </case>

        <case value="multiInput">
            <div class="clearfix" style="{$field['style']}">
            <php>
                $field['name'] = is_array($field['name'])?$field['name']:explode('|',$field['name']);
                foreach($field['name'] as $key=>$val){
            </php>
            <switch name="field['config'][$key]['type']">
                <case value="text">
                    <input type="text" name="{$val}" value="{$field['value'][$key]|htmlspecialchars}" class=" pull-left am-form-field" style="{$field['config'][$key]['style']}" placeholder="{$field['config'][$key]['placeholder']}"/>
                </case>
                <case value="select">
                    <select name="{$val}" class="pull-left am-form-field" style="{$field['config'][$key]['style']}" >
                        <php>foreach($field['config'][$key]['opt'] as $key_opt =>$option){</php>
                        <php>
                            $selected = $field['value'][$key]==$key_opt ? 'selected' : '';
                        </php>
                        <option value="{$key_opt}"{$selected}>{$option|htmlspecialchars}</option>
                        <php>}</php>
                    </select>
                </case>
            </switch>
            <php>
                }
            </php>
            </div>
        </case> 
        <default/>
        <span style="color: #f00;">错误：未知字段类型 {$field.type}</span>
        <input type="hidden" name="{$field.name}" value="{$field.value|htmlspecialchars}"/>
        </switch>
        <if condition="$field['subtitle']">
        <span class="am-form-help">（{$field.subtitle|htmlspecialchars}）</span>
        </if>
    </div>
</div>
<else/>
<input type="hidden" name="{$field.name}" value="{$field.value}"/>
</if>